local scrSize = tgm.ScreenSize

local function StartWithPlayer (pl)
	if type(pl) == "string" then
		AttemptToSay ("[DRAUGHTS] ["..pl.."] [StartGame:2]")
	else
		AttemptToSay ("[DRAUGHTS] ["..pl:UserID().."] [StartGame:2]")
	end
end

local function StartWithPlayerConCommand (ply, cmd, args)
	if not args[1] then return end
	StartWithPlayer (args[1])
end

concommand.Add ("tgm_draughts_start", StartWithPlayer)

local selectedPlayer = false

function GAME:RenderMenu ()
	selectedPlayer = false
	
	draw.SimpleText("dhhhhd", "Draughts120", scrSize * 0.5, scrSize * 0.07, Color(255,255,255,255), TEXT_ALIGN_CENTER)
	draw.SimpleText("Multiplayer Draughts", "CV50", scrSize * 0.5, scrSize * 0.18, Color(255,255,255,255), TEXT_ALIGN_CENTER)
	draw.SimpleText("bggggb", "Draughts120", scrSize * 0.5, scrSize * 0.27, Color(255,255,255,255), TEXT_ALIGN_CENTER)
	
	local x = 0
	local y = 0
	for _,pl in pairs (player.GetAll()) do
		--if pl != LocalPlayer() then
			local mx,my = self:MousePos()
				if mx > scrSize * 0.02 + (scrSize * 0.48 * x) and
				my > scrSize * 0.41 + (scrSize * 0.08 * y) and
				mx < scrSize * 0.02 + (scrSize * 0.48 * x) + scrSize * 0.48 and
				my < scrSize * 0.41 + (scrSize * 0.08 * y) + scrSize * 0.08 then
					surface.SetDrawColor (100, 100, 100, 255)
					selectedPlayer = pl
				else
					surface.SetDrawColor (50, 50, 50, 255)
				end
			surface.DrawRect (scrSize * 0.02 + (scrSize * 0.48 * x), scrSize * 0.41 + (scrSize * 0.08 * y), scrSize * 0.48, scrSize * 0.08)
			local name = pl:Nick()
			if string.len(name) > 16 then
				name = string.sub (name, 1, 14).."..."
			end
			draw.SimpleText(name, "CV30", scrSize * 0.25 + (scrSize * 0.5 * x), scrSize * 0.43 + (scrSize * 0.08 * y), Color(255,255,255,255), TEXT_ALIGN_CENTER)
			x = x + 1
			if x > 1 then x = 0; y = y + 1; end
		--end
	end
end

function GAME:OnSelectInMenu ()
	if selectedPlayer then
		StartWithPlayer (selectedPlayer)
	end
end
